home *** CD-ROM | disk | FTP | other *** search
- /*****************************************************************
- * CreateBusinessCard.c
- *
- * 8/9/94
- * By: Scott Kuechle
- * Apple Developer Technical Support
- *
- * Written in MPW 3.3.1 C
- * Compiles with 68K interfaces
- *
- * Description:
- *
- * Shows how to create a PowerTalk business card anywhere on
- * a given volume. Just create an FSSpec and call CreateBusinessCard()
- * with that FSSpec.
- *
- *****************************************************************/
-
-
-
- #include <OCE.h>
- #include <OCEAuthDir.h>
- #include <OCEMessaging.h>
- #include <OCEStandardDirectory.h>
-
- #include <files.h>
- #include <errors.h>
-
-
-
- OSErr GetIdentity();
- OSErr DoAuthentication();
- OSErr CreateBusinessCard(FSSpecPtr fsspec);
-
-
- /* globals */
- AuthIdentity gIdentity;
- RString gMyRecName = {smRoman,11,{"RecNameHere"}};
- #define gPCatName "\pDisk:BusinessCardName" // put pathname of business card here
-
-
- /*****************************************************************
- * main
- *
- *
- *****************************************************************/
-
- void main()
- {
- OSErr err;
- FSSpec fsspec;
-
- err = FSMakeFSSpec(0,0,gPCatName,&fsspec);
- if (err == fnfErr)
- err = CreateBusinessCard(&fsspec);
- }
-
-
- /*****************************************************************
- * GetIdentity
- *
- * authenticate the user
- *****************************************************************/
-
- OSErr GetIdentity()
- {
- OSErr err;
- SDPIdentityKind selectedKind;
-
- err = SDPPromptForID(&gIdentity,
- NULL,
- NULL,
- "\pPlease enter the password for your master key",
- OCEGetIndRecordType(kUserRecTypeNum),
- kSDPLocalIdentityMask,
- &selectedKind,
- NULL,
- 0); /* ignored */
- return err;
- }
-
-
- /*****************************************************************
- * DoAuthentication
- *
- * check for user authentication
- *****************************************************************/
- OSErr DoAuthentication()
- {
- OSErr err;
- AuthGetLocalIdentityPB pb;
-
- // first check if the user has already been authenticated. If so
- // we dont want to bother with authenticating again.
- err = AuthGetLocalIdentity((AuthParamBlockPtr)&pb,false);
-
- if (err != noErr)
- // user has not been authenticated, so let's do it now
- err = GetIdentity();
- else
- // user has already been authenticated
- gIdentity = pb.theLocalIdentity;
-
- return err;
- }
-
- /*****************************************************************
- * CreateBusinessCard
- *
- * build the actual business card
- *****************************************************************/
-
- OSErr CreateBusinessCard(FSSpecPtr fsspec)
- {
- OSErr err;
- DirParamBlock pb;
- RecordID rid;
-
-
-
- pb.createPersonalDirectoryPB.fsSpec = fsspec;
- pb.createPersonalDirectoryPB.fdType = kBusinessCardFileType;
- pb.createPersonalDirectoryPB.fdCreator = kPersonalDirectoryFileCreator;
- err = DirCreatePersonalDirectory(&pb);
- if (err == noErr)
- {
- pb.openPersonalDirectoryPB.fsSpec = fsspec;
- pb.openPersonalDirectoryPB.accessRequested = fsRdWrPerm;
- err = DirOpenPersonalDirectory(&pb);
- if (err == noErr)
- {
- err = DoAuthentication();
- if (err == noErr)
- {
- rid.local.cid.source = 0;
- rid.local.cid.seq = 0;
- rid.local.recordType = OCEGetIndRecordType(kUserRecTypeNum);
- rid.local.recordName = &gMyRecName;
-
- pb.addRecordPB.serverHint.aNet = 0;
- pb.addRecordPB.serverHint.aNode = 0;
- pb.addRecordPB.serverHint.aSocket = 0;
- pb.addRecordPB.identity = gIdentity;
- pb.addRecordPB.aRecord = &rid;
- pb.addRecordPB.allowDuplicate = false;
-
- err = DirAddRecord(&pb,false);
- }
- DirClosePersonalDirectory(&pb);
- }
- }
-
- return (err);
- }
-